package roguespace;

import jgame.JGObject;

public class TPlayer extends JGObject {
	/**
	 * 
	 */
	private final TheGame3 engine;

	public TPlayer(TheGame3 theGame3, double x, double y, double speed) {
		super("player", true, x, y, 1, "shipu", 0, 0, speed, speed, -1);
		this.engine = theGame3;
	}

	@Override
	public void move() {
		setDir(0, 0);
		if (this.engine.getKey(this.engine.key_left) && x > xspeed) {
			xdir = -1;
		}
		if (this.engine.getKey(this.engine.key_right) && x < this.engine.pfWidth() - 32 - yspeed) {
			xdir = 1;
		}
		if (this.engine.getKey(this.engine.key_fire)) {
			if (this.engine.countObjects("bullet", 0) < 10) {
				new JGObject("bullet", true, x, y, 4, "bary", 0, -5, -2);
				// clearKey(key_fire);
			}
		}
	}

	@Override
	public void hit(JGObject obj) {
		if (and(obj.colid, 2)) {
			this.engine.lifeLost();
		} else {
			this.engine.score += 5;
			obj.remove();
		}
	}
}